import java.util.Random;

public class Game {
    private Player player;

    public Game(Player player) {
        this.player = player;
    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }


    public String printStr(){
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        int strLength = LevelParam.LEVELS[player.getLevelNo()-1].getStrLength(); //!!!
        for (int i = 0; i <strLength; i++) {
            int rand = random.nextInt(strLength);
            switch (rand){
                case 0:
                    buffer.append(">");break;
                case 1:
                    buffer.append("<");break;
                case 2:
                    buffer.append("*");break;
                case 3:
                    buffer.append("&");break;
                case 4:
                    buffer.append("%");break;
                case 5:
                    buffer.append("#");break;
                case 6:
                    buffer.append("!");break;
            }
        }
        System.out.println(buffer);
        return buffer.toString();
    }

    public void printResult(String buffer, String str){
        long endtTime = System.currentTimeMillis();
            if (buffer.equals(str)) {
                if ((endtTime-player.getStartTime())/1000>LevelParam.LEVELS[player.getLevelNo()-1].getTimeLimit()) {
                    System.out.println("你输入太慢了，超时，退出程序！");
                    System.exit(1);
                }
                player.setElapsedTime((int)(endtTime-player.getStartTime())/1000);
                player.setCurScore(player.getCurScore()+LevelParam.LEVELS[player.getLevelNo()-1].getPerScore());
                System.out.println("输入正确，你的级别"+player.getLevelNo()+"，" +
                        "你的积分"+player.getCurScore()+"，已用时"+player.getElapsedTime()+"秒。");

            }else {
                System.out.println("输入错误，退出程序！");
                System.exit(1);
            }
    }
}
